package com.y.fund.web.mem;

import java.util.LinkedHashMap;

import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.y.fund.aacore.data.DataVo;
import com.y.fund.aacore.data.PaginationList;
import com.y.fund.aacore.vo.PagingVo;
import com.y.fund.domain.mem.MB11Group;
import com.y.fund.utils.StrUtil;
import com.y.fund.web.BaseController;
import com.y.fund.web.aavo.com.IdsForceVo;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

@ApiSort(61)
@RestController
@RequestMapping(value="api/mem/company", produces = MediaType.APPLICATION_JSON_VALUE)
@Tag(name= "企业管理")
public class CompanyController extends BaseController{

	/** 查询有企业坐标的企业行为列表 */

	@GetMapping(value = "list")
	@Operation(summary = "查询分页列表")
	@ApiOperationSupport(order = 1)
	public DataVo compList(MB11Group exp, PagingVo pvo) {
		PaginationList list=commService.findPagingByExpLikeOrderCountById(exp, pvo, null);
		return DataVo.Success(list);
	}
	
    @PostMapping("sv")
    @Operation(summary = "保存企业信息", description = "保存企业信息")
    @ApiOperationSupport(order = 4)
    public DataVo compSave(@RequestBody @Validated MB11Group obj) throws Exception{
        	
    	if(null == obj.getEmpNum()) {
    		obj.setEmpNum(0);
    	}

    	if(null == commService.addOrUpdtObj(obj)) {
        	return DataVo.Fail("创建企业失败！");
    	}

    	return DataVo.Success(obj.getId());
    }


	@GetMapping("detail/{id}")
	@Operation(summary = "企业详细信息")
	@ApiOperationSupport(order =7)
	public DataVo compDetail(@PathVariable(name="id") String id) throws Exception{
		if(StrUtil.isBlankIncNullStr(id)) {
			return DataVo.FailMustParam("id");
		}
		MB11Group dobj = commService.findObjById(MB11Group.class, id);
		LinkedHashMap<String, Object> data = new LinkedHashMap<String, Object>();
		data.put("dobj", dobj);
		return DataVo.Success(data);
	}


	@PostMapping(value = "del")
	@Operation(summary = "删除企业信息")
	@ApiOperationSupport(order = 33)
	public DataVo compDel(@RequestBody IdsForceVo idsForce) {
		if(null==idsForce.getFirstId()) {
			return DataVo.FailMustParam("id");
		}
		MB11Group dobj = commService.findObjById(MB11Group.class, idsForce.getFirstId());
		if(commService.deleteEntity(dobj)) {
			return DataVo.Success();
		}else {
			return DataVo.FailDB();
		}
	}
}